/**
 * @Title:  AttentionDynamicsActivity.java 
 * @Copyright:  XXX Co., Ltd. Copyright YYYY-YYYY,  All rights reserved 
 * @Description:  TODO<请描述此文件是做什么的> 
 * @author:  MeiYi 
 * @data:  2015-12-7 上午10:20:14 
 * @version:  V1.0 
 */

package artid.com.arttogo.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.bumptech.glide.Glide;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.InstitutionContent;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.fragment.BaseFragment;
import artid.com.arttogo.network.VolleyBasic;
import artid.com.arttogo.network.VolleyCallback;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.network.VolleyMap;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;

/**
 * 机构介绍
 * 
 * @author 熊彬
 * @data: 2015-12-7 上午10:20:14
 * @version: V1.0
 */
public class OrganizationIntroActivity extends BaseFragment {
	private View mView;
	ImageView mImgHead;
	TextView name,proj,intro,address,phone;
	private ImageLoader mImageLoader;
	Boolean isVer;//是否鉴证
	String id = "";
	View viewphone,viewaddress,viewname;
	int gznum = 0;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		Bundle args = getArguments();
		id = args != null ? args.getString("id") : "";
		super.onCreate(savedInstanceState);
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
							 Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		mView = inflater.inflate(R.layout.activity_organiazation_intro, null);
		mImgHead = (ImageView)mView.findViewById(R.id.icon_organ);
		name = (TextView)mView.findViewById(R.id.organ_name);
		proj = (TextView)mView.findViewById(R.id.organ_proj);
		intro = (TextView)mView.findViewById(R.id.organ_intro);
		address = (TextView)mView.findViewById(R.id.organ_address);
		phone = (TextView)mView.findViewById(R.id.organ_phone);
		viewphone = (View)mView.findViewById(R.id.organ_view_phone);
		viewaddress = (View)mView.findViewById(R.id.organ_view_address);
		viewname = (View)mView.findViewById(R.id.organ_view_name);
		return mView;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		reqData();
	}
	

	void reqData() {
		VolleyBasic.getInstance(getActivity()).post(
				Cache.institutionContent,
				VolleyMap.getInstance().institutionContent(
						getActivity().getIntent().getExtras().getString("id")),
				InstitutionContent.class, new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						final InstitutionContent itemContent = (InstitutionContent) vd
								.getData();

						intro.setText(itemContent.getIntroduction());
						proj.setText(itemContent.getProject());
					
						if (TextUtils.isEmpty(itemContent.getInstitutiontitle())) {
							viewname.setVisibility(View.GONE);
						}else {
							name.setText(itemContent.getInstitutiontitle());
						}
						if (TextUtils.isEmpty(itemContent.getTelphone())) {
							viewphone.setVisibility(View.GONE);
						}else {
							phone.setText(itemContent.getTelphone());
							viewphone.setOnClickListener(new View.OnClickListener() {
								
								@Override
								public void onClick(View arg0) {
									// TODO Auto-generated method stub
									Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+itemContent.getTelphone()));
									startActivity(intent);
								}
							});
						}
						if (TextUtils.isEmpty(itemContent.getAddress())) {
							viewaddress.setVisibility(View.GONE);
						}else {
							address.setText(itemContent.getAddress());
						}

						Glide.with(getActivity())
								.load(itemContent.getImgurl()+ "_" + "100" + "x10.png").asBitmap()
								.fitCenter()
								.placeholder(R.drawable.ic_menu_rotate)
								.error(R.drawable.ic_menu_rotate)
								.into(new MyBitmapImageViewTarget(mImgHead));
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
	}
	
	
}
